﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EMR_System.Controllers;

namespace EMR_System.Forms
{
    public partial class NoteForm : Form
    {
        private int apptID;

        public NoteForm()
        {
            InitializeComponent();

            apptID = -1;
        }

        public NoteForm(int apptID)
        {
            InitializeComponent();

            this.apptID = apptID;
        }

        private void addNoteBtn_Click(object sender, EventArgs e)
        {
            int noteType;

            if (noteTypeCB.SelectedText == "Office Visit")
                noteType = 1;
            else if (noteTypeCB.SelectedText == "Well Child")
                noteType = 2;
            else if (noteTypeCB.SelectedText == "Well Adult")
                noteType = 3;
            else
                noteType = 4;

            int noteID = -1;

            try
            {
                noteID = NoteController.CreateNote(noteType, apptID);
            }
            catch 
            {
                MessageBox.Show("An error occurred while trying to create note. Please try again.");
                noteTypeCB.SelectedIndex = -1;
                heightTB.Text = "";
                weightTB.Text = "";
                tempTB.Text = "";
                pulseTB.Text = "";
                respirationsTB.Text = "";
                bloodPressureTB1.Text = bloodPressureTB1.Text = "";
            }

            int height = Convert.ToInt32(heightTB.Text);
            double weight = Convert.ToDouble(weightTB.Text);
            double temp = Convert.ToDouble(tempTB.Text);
            int pulse = Convert.ToInt32(pulseTB.Text);
            int respirations = Convert.ToInt32(respirationsTB.Text);
            string bloodPressure = bloodPressureTB1.Text.Trim() + "/" + bloodPressureTB2.Text.Trim();

            Vitals v = new Vitals(height, weight, temp, pulse, respirations, bloodPressure);

            bool b1 = NoteController.EnterVitals(noteID, v);
            bool b2 = NoteController.EnterComplaint(noteID, complaintTB.Text);

            if (!b1)
                MessageBox.Show("Patient's vitals were not successfully added to note", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            if (!b2)
                MessageBox.Show("Patient's complaint were not successfully added to note", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            if (noteID != -1 && b1 && b2)
                this.Close();
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
